from ..func.move_func import MoveFunctions
from moviepy.editor import CompositeVideoClip


def move_screw_spin(clip, point1=None, point2=None, r=0, n=1, clock_direction=True, bg_size=None, duration=None):
    if duration is None:
        duration = clip.duration
    size = lambda t: clip.to_ImageClip(t).size
    (x0, y0) = clip.pos(0)
    (ix0, iy0) = size(0)
    if point1 is None:
        point1 = (x0 + ix0 / 2.0, y0 + iy0 / 2.0)
    if point2 is None:
        point2 = point1
    new_clip = clip.set_position(MoveFunctions.screw_spin(size, point1, point2, r, duration, n, clock_direction))
    if bg_size is None:
        return new_clip
    else:
        return CompositeVideoClip([new_clip], size=bg_size)
